﻿#ifndef FORMRECORDCONTROL_H
#define FORMRECORDCONTROL_H

//#include <QWidget>
#include "basewidget.h"
#include "../utils/excelhandle.h"
#include "../utils/groupitemdata.h"

class QTimer;
class BaseWidget;
class QCheckBox;
class QCheckBox;
class QSqlDatabase;
class QToolBar;
class QListWidgetItem;
class FormItemWidgetGroup;
class LoadingWidget;
namespace Ui {
class FormRecordControl;
}

class FormRecordControl : public BaseWidget
{
    Q_OBJECT
signals:
    void sig_currentItem(QString);

    void sig_showMsg(QString);
public:
    enum RecordControlType{
        RCT_PutWeigh   = 1,
        RCT_Add
    };

    explicit FormRecordControl(RecordControlType type = RCT_Add ,QWidget *parent = 0);
    ~FormRecordControl();

    bool loadDataFromSql(QString groupnum);
    bool loadDataFromSql(GroupItemData data);

    QString ImportData(int groupNum, int itemIndex = -1 , QString custfile = "");

    void setGroupData(GroupItemData data);

    void setGroupNum(QString num){m_groupNum = num;}

    GroupItemData GroupData(){return m_ItemData;}

    void setParentWidget(FormItemWidgetGroup *widget){m_parentWidget = widget;}
    FormItemWidgetGroup *getParentWidget(){return m_parentWidget;}
public slots:
    //start put weigh.
    void putWeigh(QString group);
    void putWeigh(GroupItemData groupdata);

    void startWeighOpt();

private slots:
    void updateEnable(int groupnum,int index);
    void updateToolBoxWithRecord(excelHandle rec);
    void showMessage(const QString msg);

private:
    Ui::FormRecordControl *ui;

    QWidget *widgetmsg;
    //function:
    void Init();
    void Init_Add();

    QWidget *createSelectTBar(QStringList actionList);

    QSqlDatabase dbcon(QString m_filename);
    QString getItemDBFileName(int index = -1);
    QString getItemExlFileName(int index = -1);

    void initTableWidget(QString tblName);

    void getCurrentItemData(QString stritem,bool isToFeed = false);
    void getCurrentItemData(QListWidgetItem *item);
    QStringList getTablesName(QString itemtext = "");


    FormItemWidgetGroup *m_parentWidget;

    GroupItemData m_ItemData;

    LoadingWidget *widget_load;
    QMap<int,QString> map_loadingChk;

    QMap<QString,QHash<QString,QString>> m_eachRealValue;

    QTimer *m_Puttimer;
    qint32 m_cycle;
    int m_countStartPut;//count.

    QString m_excelFileName;
    QString m_groupNum;

    QString m_defaultDataPath;

    /**
     * @brief list_preItem
     * @brief 记录当前组准备投放项目（餐数）
     */
    QStringList list_preItem;
};

#endif // FORMRECORDCONTROL_H
